package com.load.parsers;

import static com.load.utils.ContentUtil.*;

import java.util.*;

import com.database.objects.*;

public class LineParser {

	public static List<Element<?, ?>> getLinesUsingDiff(String diff, java.lang.Class<?> clazz) {
		List<Element<?, ?>> linesList = new ArrayList<Element<?, ?>>();
		if (!diff.equals("No differences")) {
			Iterator<String> lines = readLines(diff).iterator();
			Status status = defineType(lines.next());
			while (lines.hasNext()) {
				String line = lines.next();
				boolean isKey = !line.startsWith(">") && !line.startsWith("<") && !line.startsWith("---");
				if (isKey) {
					status = defineType(line);
				} else if (line.startsWith(">") || status.isDelete() && line.startsWith("<")) {
					line = line.substring(1, line.length());
					line = line.trim();
					linesList.add(new LineOO(status));
				}
			}
		}
		return linesList;
	}

	private static Status defineType(String keyDiff) {
		if (keyDiff.contains("a")) {
			return Status.ADD;
		} else if (keyDiff.contains("c")) {
			return Status.MODIFY;
		} else if (keyDiff.contains("d")) {
			return Status.DELETE;
		}
		return Status.UNKNOWN;
	}

}
